package com.yuyou.fn.report.service.impl;

import com.github.wens.framework.service.impl.SuperServiceImpl;
import com.github.wens.mybatisplus.examples.Example;
import com.github.wens.mybatisplus.plugins.Page;
import com.yuyou.fn.common.util.CriteriaUtils;
import com.yuyou.fn.report.entity.CostOfProduct;
import com.yuyou.fn.report.mapper.CostOfProductMapper;
import com.yuyou.fn.report.service.ICostOfProductService;
import com.yuyou.fn.report.vo.CostOfProductQueryVo;
import com.yuyou.fn.report.vo.ProductCostVo;
import com.yuyou.fn.report.vo.TimeAmountVo;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 *
 * CostOfProduct 表数据服务层接口实现类
 *
 */
@Service
public class CostOfProductServiceImpl extends SuperServiceImpl<CostOfProductMapper, CostOfProduct,Long> implements ICostOfProductService {

    @Override
    public List<CostOfProduct> findCostByProductId(List<Long> productIds, List<Long> mainAccountIds, Date startDate, Date endDate) {
        if (productIds==null || productIds.size()<=0 || mainAccountIds==null || mainAccountIds.size()<=0){
            return Collections.EMPTY_LIST;
        }
        Example<CostOfProduct> example=CostOfProduct.createExample();
        Example.Criteria criteria=example.createCriteria();
        criteria.andIn("mainAccountId",mainAccountIds);
        criteria.andIn("productId",productIds);
        criteria.andGreaterThanOrEqualTo("effectTime",startDate);
        criteria.andLessThanOrEqualTo("effectTime",endDate);
        return  this.findListByExample(example);
    }

    @Override
    public List<CostOfProduct> findCostByProductIdsAndFeeCategoryIds(List<Long> productIds, List<Long> mainAccountIds, Date startDate, Date endDate,List<Long> feeCategoryIds) {

        if (productIds==null || productIds.size()<=0 || mainAccountIds==null || mainAccountIds.size()<=0 || feeCategoryIds==null ||feeCategoryIds.size()<=0){
            return Collections.EMPTY_LIST;
        }
        Example<CostOfProduct> example=CostOfProduct.createExample();
        Example.Criteria criteria=example.createCriteria();
        criteria.andIn("mainAccountId",mainAccountIds);
        criteria.andIn("productId",productIds);
        criteria.andGreaterThanOrEqualTo("effectTime",startDate);
        criteria.andLessThanOrEqualTo("effectTime",endDate);
        criteria.andIn("feeCategoryId",feeCategoryIds);
        return  this.findListByExample(example);
    }

    @Override
    public Page<CostOfProduct> findProductCostPageByQueryVo(CostOfProductQueryVo costOfProductQueryVo,int pageNo,int pageSize) {

        Example<CostOfProduct> example=CostOfProduct.createExample();
        Example.Criteria criteria=example.createCriteria();
        CriteriaUtils.fillCondition(criteria,costOfProductQueryVo);
        return  this.findPageByExample(example,pageNo,pageSize);
    }

    @Override
    public List<TimeAmountVo> findProductMonthAmount(CostOfProductQueryVo costOfProductQueryVo) {
        return autoMapper.findProductMonthAmount(costOfProductQueryVo);
    }

    @Override
    public List<ProductCostVo> findProductCost(CostOfProductQueryVo costOfProductQueryVo) {
        return autoMapper.findProductCost(costOfProductQueryVo);
    }
}